package com.fh.controller;

import com.fh.config.SchedulerConfig;
import org.quartz.Job;
import org.quartz.Scheduler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

/**
 * @author whf
 * @date 2024年03月15日 15:13
 */
@RequestMapping("quartz")
@RestController
public class QuartzController {

    @Autowired
    private SchedulerConfig dynamicSchedulerConfig;

    @Autowired
    private StringRedisTemplate redisTemplate;

    @Autowired
    private Scheduler scheduler;

    @PostMapping("stop")
    public String stop(){
        dynamicSchedulerConfig.stop("dongAoJob");
        return "成功";
    }


    @PostMapping("add")
    public String add(){
        HashMap<String,Object> map = new HashMap<>();
        map.put("key","value");
        try {
            Class<? extends Job> invokeJob = (Class<? extends Job>)Class.forName("com.fh.time.InvokeJob");
            dynamicSchedulerConfig.add("dongAoJob",
                    invokeJob,
                    map
                    ,"0/5 * * * * ?");
        } catch(ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
        return "成功";
    }

    @PostMapping("index")
    public String index(){
        System.out.println("调用成功");
        return "成功";
    }

}
